<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>摩邦主页</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <!--weui.min.css-->
    <link rel="stylesheet" type="text/css" href="/static/wechat/jquery_weui/lib/weui.min.css">
    <!--jquery-weui.min.css-->
    <link rel="stylesheet" type="text/css" href="/static/wechat/jquery_weui/css/jquery-weui.min.css">

    <!--
        作者：769419833@qq.com
        时间：2017-01-13
        描述：自己的样式
    -->
    <link rel="stylesheet" href="/static/wechat/css/common.css" />
    <link rel="stylesheet" href="/static/wechat/css/homepage.css" />
    <link rel="stylesheet" href="/static/wechat/css/base.css" />
    <link rel="stylesheet" type="text/css" href="/static/wechat/css/font.css"/>
    <!--高德地图css-->
    <link rel="stylesheet" type="text/css" href="/static/wechat/css/gaodeditu.css"/>
    <style type="text/css">
        .homepage .msui_menu-list{
            line-height: 1rem;
            display: block;
            text-align: center;
            padding: .5rem 0;
            width: 4rem;
        }
        .msui_tabMenu-active1{
            color:#fc4208;
        }
        .msui_tabMenu-active1:hover,.msui_tabMenu-active1:focus{
            color:#fc4208;
        }
        #line{
            width: 3rem;
        }
        .msui_menu-baseline {border-bottom-width:2px;}
        .mt24{
            margin-top: 2.4rem;
        }
    </style>
</head>
<body>



<!--<div class="Fixed_div"></div>-->
<a class="Fixed_div" style="top:5rem;z-index:9;" href="{:url('index_list')}"></a>


<!--
    作者：769419833@qq.com
    时间：2017-01-14
    描述：地图页面
-->
<div id="allmap">

    <div class="top_fix">
        <!--
        作者：769419833@qq.com
        时间：2017-01-13
        描述：头部
   -->
        <div class="homepage_nav">
            <!--<a class="msui_navTop-back" href="javascript:history.back();"><i class="micon-back"></i></a>-->
            <i class="heade_por">
                <img src="{$member.headimgurl|get_img_url}" onerror="this.src='/static/wechat/images/tui_03.jpg'" style="border-radius:50%" />
            </i>
            <h1 class="home_page_title">摩邦</h1>
            <a class="to_messages" href="{:url('message/index', ['type' => 0])}">
                <!--<i class="message"></i>-->
            </a>

        </div>
        <!--
        	作者：769419833@qq.com
        	时间：2017-01-14
        	描述：维修拖车保养列表
        -->
        <div class="msui_menu homepage">
            <div class="msui_menu-mask">
                <ul class="msui_menu-bd js-menu">
                    {volist name="member.server_items" id="v"}
                    <li class="msui_menu-li" dataTab="{$i}" dataID="{$v.id}" dataIcon="{$v.icon}?v=1"><a class="msui_tabMenu-active{$i} msui_menu-list fs08 cl-9999">{$v.item_name}</a></li>
                    {/volist}
                    <!-- 用于动画的层 -->
                    <div id="line" class="msui_menu-baseline"></div>
                </ul>
            </div>
            <!--<div class="msui_menu-dropdown">-->
                <!--<i class="micon-down"></i>-->
            <!--</div>-->
        </div>

    </div>
    <!--
    作者：769419833@qq.com
    时间：2017-01-14

    描述：底部点击查看详情
    -->


    <div class="footer">
        <div class="footer_x">
            <a class="closs_xq" onclick="clossxp()">
            </a>
        </div>
        <!--滑动选择店-->
        <div>
            <ul class="slide_xz">
                <!--
<li>
<i class="dian_img"></i>
<h2 class="name_of_shop">老司机修理店1<h2>
<span class="order_num">202单</span>
<a class="dian_recom">优店推荐</a>
</li>

                -->
            </ul>
        </div>

        <div class="footer_c">
            <i class="red_mark">

            </i>
            <span class="juti_address open-popup" data-target="#Pop">获取地址...</span>
        </div>
    </div>

</div>
<a href="javascript:;" class="open-popup PLorder_" data-target="#Pop"></a>
<div id="Pop" class="weui-popup__container popup-bottom">
    <div class="weui-popup__overlay"></div>
    <div class="weui-popup__modal" style="background-color:transparent ;text-align: center;">
        <div class="parele">
            <div class="Servise_time">
                <span>服务时间</span>
                <!--<h1 class="fs07">现在</h1>-->
                <input class="weui-input" id="time-format" type="text" placeholder="现在">
            </div>
            <!--定位到区-->
            <div class="Servise_addres" style="display:none;">
                <i></i>
                <form onsubmit="return false">
                    <input id="start" class="Servise_input" type="text" placeholder="获取省市区..." />
                </form>
            </div>
            <div class="Servise_addres" style="display:none;">
                <i></i>
                <form onsubmit="return false">
                    <input id="sJiedao" class="Servise_input" placeholder="获取街道..." value="" />
                </form>
            </div>
            <div class="Servise_addres">
                <i></i>
                <form onsubmit="return false" style="width:100%;">
                    <input id="sAdd" class="Servise_input" placeholder="填写详细地址" value="" />
                </form>
            </div>
            <div class="Servise_description1" style="display:none">
                <i class="ipt_yuan"></i>
                <form onsubmit="return false">
                    <input id="sName" class="Servise_input" placeholder="填写联系人" value="{$member.proposer|default='匿名'}" />
                </form>
            </div>
            <div class="Servise_description1" style="display:none">
                <i class="ipt_yuan"></i>
                <form onsubmit="return false">
                    <input id="sTel" class="Servise_input" placeholder="填写联系方式" value="{$member.phone0|default=$member.phone|default=''}" />
                </form>
            </div>
            <div class="Servise_description1">
                <i class="ipt_yuan"></i>
                <form onsubmit="return false">
                    <input id="sMsg" class="Servise_input" placeholder="问题描述(可选)" value="" />
                </form>
            </div>
            <!--<div class="Servise_description1">-->
                <!--<i class="ipt_yuan"></i>-->
                <!--<form onsubmit="return false">-->
                    <!--<input id="sDateTimeLocal" placeholder="日期时间" value="" type="datetime-local" />-->
                <!--</form>-->
            <!--</div>-->
            <div class="Servise_description2">
                <!--<span>上门服务</span>-->
                <input class="weui-input" id="mobile" type="text" value="" placeholder="上门处理">

                <div></div>
                <!--<span>添加图片</span>-->
                <a href="javascript:;" class="open-popup" data-target="#Popup2" id="add_img_but">添加图片</a>
            </div>
        </div>
        <div class="transparent_">

        </div>
        <!--<input type="hidden" name="lat" id="sLat" /><input type="hidden" name="lng" id="sLng" />-->
        <button class="Servise_placeorder fs08 close-popup" disabled="disabled">
            确认下单
        </button>
    </div>
</div>

<!--图片弹出框-->
<div id="Popup2" class="weui-popup__container popup-bottom">
    <div class="weui-popup__overlay"></div>
    <div class="weui-popup__modal">
        <div class="navbar">
            <div class="msui_nav msui_navTop" style="border-bottom: 1px solid #cccccc;">
                <a class="msui_navTop-back open-popup" data-target="#Pop"><i class="micon-back"></i></a>
                <h1 class="msui_navTop-title">添加图片</h1>
            </div>

            <div class="tjimg mt24">
                <!--<img src="/static/wechat/images/1.jpg"/>-->
                <div class="weui-uploader__input-box" id="marg">
                    <input id="uploaderInput" class="weui-uploader__input" type="file" accept="image/*" multiple="multiple" />
                </div>
            </div>

            <button class="tjtu open-popup" data-target="#Pop">确认</button>
            <p style="clear:both;text-align:center;font-size:12px;color:#999;line-height:1rem;">（长按图片删除）</p>

        </div>
    </div>
</div>



<div id="loadingToast" style="display:none;">
    <div class="weui-mask_transparent"></div>
    <div class="weui-toast">
        <i class="weui-loading weui-icon_toast"></i>
        <p class="weui-toast__content">数据加载中...</p>
    </div>
</div>
<div id="iosDialog2" class="js_dialog" style="display:none;">
    <div class="weui-mask_transparent"></div>
    <div class="weui-dialog">
        <div class="weui-dialog__bd">弹窗内容，告知当前状态、信息和解决方法，描述文字尽量控制在三行内</div>
        <div class="weui-dialog__ft">
            <a href="javascript:$('#iosDialog2').hide();" class="weui-dialog__btn weui-dialog__btn_primary">知道了</a>
        </div>
    </div>
</div>
<div class="page msg_panel js_show">
    <div class="weui-msg">
        <div class="weui-msg__text-area">
            <div id="inPanel"></div>
        </div>
        <div class="weui-msg__opr-area">
            <p class="weui-btn-area">
                <a href="javascript:;" onclick="$('.msg_panel').animate({'left':'100%'},200)" class="weui-btn weui-btn_primary">确定</a>
                <!--<a href="javascript:history.back();" class="weui-btn weui-btn_default">辅助操作</a>-->
            </p>
        </div>
    </div>
</div>
<div class="page msg_success js_show">
    <div class="weui-msg">
        <div class="weui-msg__icon-area"><i class="weui-icon-success weui-icon_msg"></i></div>
        <div class="weui-msg__text-area">
            <h2 class="weui-msg__title">下单成功</h2>
            <p class="weui-msg__desc">请等待商家接单...</p>
        </div>
        <div class="weui-msg__opr-area">
            <p class="weui-btn-area">
                <a href="{:url('orders/index')}" class="weui-btn weui-btn_primary">查看我的订单</a>
                <!--<a href="javascript:history.back();" class="weui-btn weui-btn_default">辅助操作</a>-->
            </p>
        </div>
    </div>
</div>
</body>
<!-- jquery-2.1.4 -->
<script type="text/javascript" src="/static/wechat/jquery_weui/lib/jquery-2.1.4.js"></script>
<!-- jquery-weui.min.js -->
<script type="text/javascript" src="/static/wechat/jquery_weui/js/jquery-weui.min.js"></script>

<!--jquery-city-picker.min.js-->
<script type="text/javascript" src="/static/wechat/jquery_weui/js/data-picker1.js" ></script>
<script type="text/javascript" src="/static/wechat/jquery_weui/js/city-picker.js" ></script>
<!--
    作者：769419833@qq.com
    时间：2017-01-13
    描述：自己的js<script type="text/javascript" src="/static/wechat/js/homepage.js" ></script>
-->
<script type="text/javascript" src="/static/wechat/js/common.js" ></script>
<script type="text/javascript" src="/static/wechat/js/error_code.js" ></script>
</html>
<!--高德地图
<script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key=9a8d0d7e358d9d80f7f61a1989ba35a0"></script>
<script type="text/javascript" src="/static/wechat/js/gaodeditu.js" ></script>
-->

<!-- PJ 0 -->
<script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key=9a8d0d7e358d9d80f7f61a1989ba35a0&plugin=AMap.Riding,AMap.Driving,AMap.Walking,AMap.Transfer"></script>
<script type="text/javascript">
/*点击border-bottom移动动画*/
function tabLine(Tparent,target,line,speed){
    if(Tparent.length==0||target.length==0||line.length==0){
        return;
    }

    line.css('marginLeft',$('.msui_tabMenu-active4').offset().left);
    target.on('click',function() {
        var left = $(this).offset().left - Tparent.offset().left+"5";
        if (line.is(":animated")) {
            line.stop(true,true);
        }
        line.animate({
            marginLeft:left
        }, speed);
    })
}
/*长度限定*/
function textNumber(target,number){
    target.on('keyup',function(){
        if($(this).val().length>=number){
            var num=$(this).val().substr(0,number);
            $(this).val(num);
        }
    })
}
/*picker*/
function userPicker(target,title,content){
    target.picker({
        title: title,
        cols: [{
            textAlign: 'center',
            values: content
        }]
    });
}

tabLine($(".msui_menu-li"),$(".msui_menu-list"),$(".msui_menu-baseline"),300);
$('.msui_menu-bd').width($('.msui_menu-bd').find('.msui_menu-li').width()*$('.msui_menu-bd').find('.msui_menu-li').length+20+'px');

/*订单分类*/
$('.top_fix .js-menu li').on('click',function(){
    var dataTab=$(this).attr('dataTab');
    var that=this;
    $('.top_fix .js-menu li').find('a').each(function(){
        if($(this).hasClass('msui_tabMenu-active1')){
            $(this).removeClass('msui_tabMenu-active1');
        }
        $(that).find('a').addClass('msui_tabMenu-active1');
    })
    $('.top_fix .js-list').each(function(){
        $(this).css('display','none');
        if($(that).attr('dataTab')==1){
            $('.refund .js-list').each(function(){
                $(this).css('display','block');
            })
        }
        if($(this).attr('dataOrder')==$(that).attr('dataTab')){
            $(this).css('display','block');
        }
    });
});

//服务方式
$("#mobile").picker({
    title: "请选择服务方式",
    cols: [
        {
            textAlign: 'center',
            values: ['上门服务', '到店消费']
        }
    ],
    onChange: function(p, v, dv) {
        console.log(p, v, dv);
    },
    onClose: function(p, v, d) {
        console.log("close");
    }
});
//选择日期
$("#time-format").datetimePicker({
    title: '请选择服务时间',
    yearSplit: '年',
    monthSplit: '月',
    dateSplit: '日',
    min: function () {
        var t=new Date();
        return t.getFullYear()+'-'+ (t.getMonth()+1)+'-'+ t.getDate()

    },
    times: function () {
        return [  // 自定义的时间
            {
                values: (function () {
                    var hours = [];
                    for (var i=0; i<24; i++) hours.push(i > 9 ? i : '0'+i);
                    return hours;
                })()
            },
            {
                divider: true,  // 这是一个分隔符
                content: '时'
            },
            {
                values: (function () {
                    var minutes = [];
                    for (var i=0; i<59; i++) minutes.push(i > 9 ? i : '0'+i);
                    return minutes;
                })()
            },
            {
                divider: true,  // 这是一个分隔符
                content: '分'
            }
        ];
    },
    onChange: function (picker, values, displayValues) {
        console.log(values);
    }
});






//改写原生的对话框
function sAlert(s){
    $('#iosDialog2').show();
    $('#iosDialog2 .weui-dialog__bd').html(s);
}
window.alert = function(s){sAlert(s);}


window.now_center_lat = window.now_center_lng = 0;
window.my = new Object();//存放用户的定位信息
window.in = new Array();//存放所有商户的定位信息
//window.in_id = 0;//存放选定商户的定位信息(20170204不能指定,要抢)
window.in_type = 2;//2:维修,3:拖车,4:保养,5:购车,6:保险
var mapObj,geolocation,dragTime,now_center_marker;


//初始化地图
$("#allmap").prepend('<div id="container" tabindex="0"></div>');
//$("#allmap").prepend('<img src="http://webapi.amap.com/theme/v1.3/markers/n/mark_r.png" style="display:block;position:absolute;top:50%;left:50%;z-index:9999;width:19px;height:31px;margin:-31px 0 0 -9px;" />');
mapObj = new AMap.Map('container',{
    resizeEnable: true,
    zoom: 15,
    //zoomEnable: false,	//禁止放大缩小
    //dragEnable: false,	//禁止拖动
//    mapStyle:'fresh'
});
window.mapRiding = new AMap.Riding({map: mapObj});//骑行
window.mapDriving = new AMap.Driving({map:mapObj});//驾车
window.mapWalking = new AMap.Walking({map:mapObj});//步行
window.mapTransfer = new AMap.Transfer({map:mapObj,panel:"inPanel"});//公交


window.setInterval(function(){
    var num = $(".tjimg img").length;
    if(num){
        $('#add_img_but').html('有'+num+'张图片');
    }else{
        $('#add_img_but').html('添加图片');
    }
},999);

$('.ipt_yuan').addClass('input_yuan2');
$('.Servise_placeorder').addClass('Servise_placeorder2').removeAttr('disabled');



$(function(){
    $('#loadingToast').fadeIn();
    //监控用户位置
    mapObj.plugin('AMap.Geolocation', function () {
        geolocation = new AMap.Geolocation({
            enableHighAccuracy: true,//是否使用高精度定位，默认:true
            timeout: 30000,          //超过30秒后停止定位，默认：无穷大
            maximumAge: 0,           //定位结果缓存0毫秒，默认：0
            convert: true,           //自动偏移坐标，偏移后的坐标为高德坐标，默认：true
            showButton: true,        //显示定位按钮，默认：true
            buttonPosition: 'LB',    //定位按钮停靠位置，默认：'LB'，左下角
            buttonOffset: new AMap.Pixel(10,10),//定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
            showMarker: true,        //定位成功后在定位到的位置显示点标记，默认：true
            showCircle: false,        //定位成功后用圆圈表示定位精度范围，默认：true
            panToLocation: true,     //定位成功后将定位到的位置作为地图中心点，默认：true
            zoomToAccuracy:true,      //定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
            extensions:'base'
        });
        //markerOptions: window.my_dingdan,
        mapObj.addControl(geolocation);//开始监控
        AMap.event.addListener(geolocation, 'complete', onComplete);//返回定位信息//onComplete
        AMap.event.addListener(geolocation, 'error', onError);      //返回定位出错信息
        $(".amap-geo").trigger("click");
    });

    //开始拖拽地图时
    mapObj.on("dragstart", function(){
        window.clearTimeout(dragTime);
    });
    //拖拽地图过程中
    mapObj.on("dragging", function(){
        //window.clearTimeout(dragTime);
        if(window.now_center_marker){
            window.now_center_marker.setPosition(mapObj.getCenter());
            window.now_center_lat = mapObj.getCenter().lat;
            window.now_center_lng = mapObj.getCenter().lng;
        }
    });
    //停止拖拽地图时
    mapObj.on("dragend", function(){
        dragTime = setTimeout(function() {
            console.log(mapObj.getCenter());
            if(
                    (window.my.position.lng - mapObj.getCenter().lng)<-0.008
                    || (window.my.position.lng - mapObj.getCenter().lng)>0.008
                    || (window.my.position.lat - mapObj.getCenter().lat)<-0.01
                    || (window.my.position.lat - mapObj.getCenter().lat)>0.01
            ){
                //window.my.position = tmp;
                getData(
                    window.in_type
                    ,mapObj.getCenter().lng
                    ,mapObj.getCenter().lat
                );
            }
        },888);

        //逆推地址
        $.ajax({
            type:"get",
            cache:false,
            dataType:"json",
            url:"{:url('base/map_get_address')}?lat="+mapObj.getCenter().lat+"&lng="+mapObj.getCenter().lng,
            error:function(s){
                //$('#loadingToast').fadeOut();
            },
            success:function(d){
                if(d.status==1){
                    var tmpAddress = d.regeocode.formatted_address.split(d.regeocode.addressComponent.township)[1];
                    $('#sAdd').val(tmpAddress);
                }else{
                    //alert(d.info);
                }
            }
        });

    });
});



//点击个人中心
$(".heade_por").click(function(){
    window.location.href = '{:url("member/index")}';
});

//添加图片
$("#uploaderInput").change(function(){
    if($(".tjimg img").length>4){
        alert('只能添加5张图片');
    }else{
        $('#loadingToast').show();
        window.setTimeout(function(){
            var formData = new FormData();
            formData.append("type","order");
            formData.append("img",$("#uploaderInput")[0].files[0]);
            $.ajax({
                url: '{:url("Base/get_upload_img")}',
                type: 'POST',
                data: formData,
                async: false,
                cache: true,
                contentType: false,
                processData: false,
                dataType:"json",
                success: function (d) {
                    $('#loadingToast').fadeOut();
                    if(!d.code){
                        alert(d.msg);
                    }else{
                        var path = SCOPE.image_host_url+d.data.path;
                        $(".tjimg").prepend('<img src="'+path+'" ontouchstart="del_uploads_img(this)" ontouchend="del_uploads_img_clear()" />');
                    }
                },
                error: function (d) {
                    alert('网络异常');$('#loadingToast').fadeOut();
                }
            });
        },666);

    }
});


//确认下单
window.Servise_placeorder_check = true;
$(".Servise_placeorder").click(function(){



    var formData = new Object();
    formData.repair_id = 0;
    var tmpTime = $("#time-format").val().replace("年","-").replace("月","-").replace("日","").replace("时",":").replace("分","");
    formData.server_time = tmpTime;
    var tmpMode = ($("#mobile").val()=="到店处理"?1:2);
    formData.service_mode = tmpMode;
    formData.msg = $("#sMsg").val();
    formData.address = $("#sAdd").val();
    formData.apply_person = $("#sName").val();
    formData.phone = $("#sTel").val();
    formData.type = window.in_type;
    formData.lng = window.now_center_lng;
    formData.lat = window.now_center_lat;

    try{
        formData.province = $("#start").attr("data-codes").split(",")[0];
        formData.city = $("#start").attr("data-codes").split(",")[1];
        formData.area = $("#start").attr("data-codes").split(",")[2];
        formData.street = $("#sJiedao").attr("data");
    }catch(e){}
    formData.img1 = formData.img2 = formData.img3 = formData.img4 = formData.img5 = "";
    for(i=0;i<$(".tjimg img").length;i++){
        eval("formData.img"+(i+1)+" = '"+$(".tjimg img")[i].src.split(window.location.host)[1]+"';");
    }

    if(formData.address.length<3){alert("请输入详细地址");return false;}
    //if(formData.apply_person.length<1){alert("请输入联系人");return false;}
    //if(formData.phone.length<6){alert("请输入联系方式");return false;}
    //if(formData.msg.length<2){alert("请输入问题描述");return false;}

    $('#loadingToast').fadeIn();
    if(window.Servise_placeorder_check==false){
        return false;
    }
    window.Servise_placeorder_check = false;
    $.ajax({
        url:"{:url('index/up_data')}",
        type: 'POST',
        data: formData,
        dataType:"json",
        error:function(s){
            window.Servise_placeorder_check = true;
            alert('网络异常');
            $('#loadingToast').fadeOut();
        },
        success:function(d){
            window.Servise_placeorder_check = true;
            if(d.code!=200){
                var code = msg.code;
                $.alert(error_code[code]);
            }else{
                $(".msg_success").animate({"left":"0px","display":"block"},200);
                //window.location.href = "order?id=" + d.data;
            }
            $('#loadingToast').fadeOut();
        }
    });

});




//更换商家类型后重新获取数据
$(".msui_menu-li").click(function(){
    clearData();
    clearRoute();
    getData($(this).attr('dataID'),window.now_center_lng, window.now_center_lat);
});

//解决iphone下单时无法关闭问题
$(".weui-popup__overlay").click(function(){
    return true;
});


//长按删除图片
function del_uploads_img(o){
    window.t_img = o;
    window.t_uploads = setTimeout(function(){
        if(window.confirm("确定删除?")){
            var formData = new Object();
            formData.img = window.t_img.src.split(window.location.host)[1];
            $.ajax({
                url: '{:url("Base/del_upload_img")}' ,
                type: 'POST',
                data: formData,
                dataType:"json",
                success: function (d) {
                    if(d.code==200){
                        window.t_img.parentNode.removeChild(window.t_img);
                    }else{
                        alert('无法删除文件');
                    }
                },
                error: function (d) {
                    alert('网络异常');
                }
            });

        }
    },666);
}
//取消长按删除图片
function del_uploads_img_clear(){
    window.clearTimeout(window.t_uploads);
}


//处理定位信息
function onComplete(data){
    $('#loadingToast').fadeOut();
    window.console.log(JSON.stringify(data));
    if(data.info=="SUCCESS"){

        window.my = data;
        window.now_center_lat = data.position.lat;
        window.now_center_lng = data.position.lng;
        if(window.now_center_marker){
            window.now_center_marker.setMap(null);
        }
        window.now_center_marker = new AMap.Marker({
            map: mapObj,
            //offset: new AMap.Pixel(-18,-40),
            position: [data.position.lng,data.position.lat],
            zIndex: 9999,
            icon:  "http://webapi.amap.com/theme/v1.3/markers/n/mark_r.png"
        });

        $(".msui_menu-li[dataID='"+window.in_type+"']").trigger("click");
        $("#start").attr("value",window.my.addressComponent.province+" "+window.my.addressComponent.city+" "+window.my.addressComponent.district);
        var tmpDZ = window.my.formattedAddress;
        tmpDZ = tmpDZ.substr(tmpDZ.indexOf("省")+1);
        tmpDZ = tmpDZ.substr(tmpDZ.indexOf("市")+1);
        tmpDZ = tmpDZ.substr(tmpDZ.indexOf("区")+1);
        tmpDZ = tmpDZ.replace(window.my.addressComponent.township,"");
        $("#sAdd").val(tmpDZ);
        $(".juti_address").html(tmpDZ+"附近");

        $("#start").cityPicker({
            title: "选择省，市，区",
            onChange: function (picker, values, displayValues) {
                return true;
            },
            onClose: function(r1){
                //console.log(r1);
                $("#sJiedao").val("");
                $("#sJiedao").attr("data","");

                $('#loadingToast').fadeIn();
                $.ajax({
                    type:"get",
                    cache:false,
                    dataType:"json",
                    url:"{:url('Base/get_street')}?area="+r1.value[2]+"",
                    error:function(s){
                        $('#loadingToast').fadeOut();
                        alert('网络异常');
                    },
                    success:function(d){
                        $('#loadingToast').fadeOut();
                        if(d.code!=200){
                            alert(d.msg);
                        }else{

                            var tmp_values = new Array();
                            var tmp_displayValues = new Array();
                            for(i=0;i<d.data.length;i++){
                                tmp_values[i] = d.data[i].region_id;
                                tmp_displayValues[i] = d.data[i].region_name;
                                if(window.my.addressComponent.township==tmp_displayValues[i]){
                                    $("#sJiedao").attr("value",tmp_displayValues[i]);
                                    $("#sJiedao").attr("data",tmp_values[i]);
                                    $("#sJiedao").val(tmp_displayValues[i]);
                                }
                            }

                            try{
                                $("#sJiedao").data().picker.cols[0].values = tmp_values;
                                $("#sJiedao").data().picker.cols[0].displayValues = tmp_displayValues;
                            }catch(e){
                                $("#sJiedao").picker({
                                    title: "请选择街道",
                                    cols: [
                                        {
                                            textAlign: 'center',
                                            values: tmp_values,
                                            displayValues: tmp_displayValues
                                        }
                                    ],
                                    onChange: function (picker, values, displayValues) {
                                        return true;
                                    },
                                    onClose: function(r2) {
                                        try{
                                            $("#sJiedao").val(r2.displayValue[0]);
                                            $("#sJiedao").attr("data",r2.value[0]);
                                        }catch(e){}
                                        //console.log(r2);
                                    }
                                });
                            }
                            //获取一下街道对应的data-codes
                            //$("#sJiedao").data().picker.open();$("#sJiedao").data().picker.close();

                        }
                    }
                });

            }
        });
        //获取一下省市区对应的data-codes
        $("#start").data().picker.open();$("#start").data().picker.close();

    }else{
        alert("没有成功获取到您的位置<br>请重新访问...<br>(" + data.message + ")");
    }

}
//处理定位出错信息
function onError(e){
    if( window.navigator.userAgent.indexOf("wechatdevtools")!=-1 ){
        //微信调试工具测试数据
        var data = {"type":"complete","info":"SUCCESS","status":1,"x3":"jsonp_185217_","position":{"M":28.20701,"I":112.87018,"lng":112.87018,"lat":28.20701},"message":"Get ipLocation success.Get address success.","location_type":"ip","accuracy":null,"isConverted":true,"addressComponent":{"citycode":"0731","adcode":"430104","businessAreas":[{"name":"麓谷","id":"430104","location":{"M":28.21402974876848,"I":112.88941027093597,"lng":112.88941,"lat":28.21403}}],"neighborhoodType":"","neighborhood":"","building":"","buildingType":"","street":"麓松路","streetNumber":"189号","province":"湖南省","city":"长沙市","district":"岳麓区","township":"麓谷街道"},"formattedAddress":"湖南省长沙市岳麓区麓谷街道麓松路189号延农5期","roads":[],"crosses":[],"pois":[]};
        onComplete(data);
    }else{
        $('#loadingToast').fadeOut();
        alert("无法获取您的位置<br>请重新访问...<br>(" + e.message + ")");
    }
}




//标记上面出现提示框
var infoWindowObj = new AMap.InfoWindow({offset:new AMap.Pixel(0,-30)});
function inBoxOpen(e) {
    infoWindowObj.setContent(e.target.content);
    infoWindowObj.open(mapObj, e.target.getPosition());
    mapObj.setCenter(e.target.getPosition());
}

//清除地图上的标记
function clearData(){
    for(var x in window.in){
        if(window.in[x]){
            window.in[x].setMap(null);
            window.in[x] = undefined;
        }
    }
}
//清除地图上的路线
function clearRoute(){
    try{
        window.mapRiding.clear();
        window.mapDriving.clear();
        window.mapWalking.clear();
        window.mapTransfer.clear();
    }catch(e){console.log(e.message)}
}

//获取路线
function inRoute(o,type,id){
    clearRoute();
    var tmpPosition = [window.now_center_lng,window.now_center_lat];
    if(type==1) {
        window.mapDriving.search(tmpPosition,window.in[id].getPosition(),function(status,result){inRouteCall(status,result)});//驾车
    }else if(type==2) {
        window.mapWalking.search(tmpPosition,window.in[id].getPosition(),function(status,result){inRouteCall(status,result)});//步行
    }else if(type==3) {
        $('.msg_panel').animate({'left':0},200);
        window.mapTransfer.search(tmpPosition,window.in[id].getPosition());//公交(没有回调)
    }else{
        window.mapRiding.search(tmpPosition,window.in[id].getPosition(),function(status,result){inRouteCall(status,result)});//骑行
    }

    var tmpA = o.parentNode.getElementsByTagName("a");
    for(i=0;i<tmpA.length;i++){
        tmpA[i].className = "";
    }
    o.className = "on";
    window.inRouteObj = o;

}
//获取路线回调
function inRouteCall(s,r){
    if(s=="complete"){
        if(r.info.toUpperCase()=="OK"){
            var tmpHtml = "距离<b>"+(r.routes[0].distance/1000).toFixed(1)+"</b>公里" +
                    ",预计用时<b>"+(r.routes[0].time/60).toFixed(1)+"</b>分钟";
            window.inRouteObj.parentNode.getElementsByTagName("span")[0].innerHTML = tmpHtml;
            /*setTimeout(function(){mapObj.setZoom(mapObj.getZoom()-1)},888);*/
        }
    }

}

//在地图上标记
function showData(d){
    var tmpStr = "";
    for(i=0;i<d.length;i++){
        var tmpID = d[i].id;
        if( typeof(window.in[tmpID])!="object" ){

            window.in[tmpID] = new AMap.Marker({
                map: mapObj,
                offset: new AMap.Pixel(-18,-40),
                position: [d[i].lon,d[i].lat],
                icon:  $(".msui_menu-li[dataID='"+window.in_type+"']").attr("dataIcon")
            });
            window.in[tmpID].content = '<div class="inBox">' +
                    '<h2><img src="'+d[i].cover+'" />'+d[i].repair_name+'</h2>' +
                    '<p>地址 : '+d[i].address+'</p>' +
                    '<p>路线 : <a onclick="inRoute(this,0,'+tmpID+')">骑行</a><a onclick="inRoute(this,1,'+tmpID+')">驾车</a><a onclick="inRoute(this,2,'+tmpID+')">步行</a><a onclick="inRoute(this,3,'+tmpID+')">公交</a>' +
                    '<span class="in_f"></span></p>' +
                    '</div>';
            //<a href="javascript:openPop('+tmpID+');" class="open-popup" data-target="#Pop">我要下单</a>
            window.in[tmpID].on('click', inBoxOpen);
            //window.in[tmpID].emit('click',{target: window.in[tmpID]});//点开第一个
        }
        tmpStr += '<li><i class="dian_img"></i><h2 class="name_of_shop">'+d[i].repair_name+'<h2><span class="order_num">202单</span><a class="dian_recom">优店推荐</a></li>';
    }
    $(".slide_xz").html(tmpStr);
}

//获取商家数据
function getData(type,lng,lat){

    //获取商家类型
    window.in_type = type;

    //设为中心点
    mapObj.setCenter([lng,lat]);

    $('#loadingToast').fadeIn();
    $.ajax({
            type:"get",
            cache:false,
            dataType:"json",
            url:"{:url('index/get_data')}?type="+window.in_type+"&lng="+lng+"&lat="+lat+"&zoom="+mapObj.getZoom(),
            error:function(s){
                $('#loadingToast').fadeOut();
                alert('网络异常');
            },
            success:function(d){
                $('#loadingToast').fadeOut();
                if(d.code!=200){
                    alert(d.msg);
                }else{
                    showData(d.data);
                }
            }
        });

}



</script>
<!-- PJ 1 -->
